package com.cassiopae.services;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cassiopae.dao.ProfileDaoImpl;
import com.cassiopae.entity.Profile;
/**
 * Servlet implementation class ProfileServlet
 */
@WebServlet("/ProfileServlet")
public class ProfileServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
     
	ProfileDaoImpl profileDaoImpl = new ProfileDaoImpl();
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			doPost(request, response);
		}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		
		String database = request.getParameter("Base");
		String schemaCible = request.getParameter("Target_schema");
		String passwordCible = request.getParameter("Target_pwd");
		String dbVersion = request.getParameter("dbVersion");
		String appliVersion = request.getParameter("appliVersion");
		String impSchema = request.getParameter("impSchema");
		
		Profile profile = new Profile(database, schemaCible, passwordCible, dbVersion, appliVersion, null, null, impSchema);
		
		
		if(profileDaoImpl.create(profile)){
			List<Profile> profiles = profileDaoImpl.getAll();
			request.getSession().setAttribute("LISTPROFIL", profiles);
			getServletContext().getRequestDispatcher("/listProfile.jsp").forward(request, response);
		}
		
		
	}

}
